﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net;
using System.Net.Mail;
using System.Data;
using System.Windows.Forms;
using SWEN_HMS.Classes;

namespace SWEN_HMS.UserModule
{
    public partial class retrieve : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            int staffID = Convert.ToInt32(tbxStaffID.Text);
           
            staff s = userDB.getDetailByStaffID(staffID);
            string Staffname=s.staffName;
            try
            {
                EncodingAndDecodingcs de = new EncodingAndDecodingcs();
                MailMessage mail = new MailMessage();
                mail.From = new MailAddress("swenhms@gmail.com");
                mail.To.Add(s.email);
                mail.Subject = "Password Recovery";
                mail.Body = "Dear " + Staffname + "," + Environment.NewLine + Environment.NewLine + "Here is your request to retrieve your password that you had forgotten," + Environment.NewLine + Environment.NewLine+"Passwords:"+
                    de.Decode(s.password) + Environment.NewLine + Environment.NewLine + "This is a generated E-mail. Please do not reply" + Environment.NewLine + Environment.NewLine + "Best Regards" + Environment.NewLine + " Delonix Regia Team";
               
                SmtpClient smtp = new SmtpClient("smtp.gmail.com");
                smtp.Credentials = new NetworkCredential("swenhms@gmail.com", "HMS12345");
                smtp.Port = 587;
                smtp.EnableSsl = true;
                smtp.Send(mail);
                System.Windows.Forms.MessageBox.Show("Please check your Email for your retrieved password.");
                Response.Redirect("Login.aspx");
            }
            catch
            {
                lblmessage.Text="Invalid StaffID!";
            }

        }
    }
}